package com.maojianjie.aimee.utils;

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.time.Instant;
import java.util.Random;

public class RandomUtil
{
	public static String string(String pre, int length) throws NoSuchAlgorithmException, UnsupportedEncodingException
	{
		String random = String.valueOf(Instant.now().toEpochMilli()) + String.valueOf(new Random().nextInt(9999));
		if (pre == null || pre.isEmpty())
		{
			return MD5Util.encrypt(random).substring(0, length);
		}
		return (pre + "_" + MD5Util.encrypt(random)).substring(0, length);
	}
}
